package com.hspedu.smallchange;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    //1.完成显示菜单，并可以选择菜单，给出对应提示
    public static void main(String[] args) {

        double balance = 0;
        //定义相关变量
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        String key = "";
        SmallChangeSys smallChangeSys = new SmallChangeSys();
        double money = 0;
        String details = " ";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//日期格式化
        do{
            System.out.println("=======零钱通菜单=======");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退出");

            System.out.println("请选择（1-4）:");
            key = scanner.next();

            //使用switch分支控制
            switch(key){
                case "1":
                    System.out.println("==========1 零钱通明细==========");
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println("2 收益入账");
                    System.out.println("请输入入账金额：");

                    while (true){
                        money = scanner.nextDouble();
                        if (money<=0){
                            System.out.println("请输入大于0的数");
                        }else{
                            balance += money;
                            //拼接收益入账信息
                            Date date = new Date();
                            details += "收益入账\t" + money + "\t" + simpleDateFormat.format(date) +"\t"+balance+"\n";
                            System.out.println(details);
                            break;
                        }

                    }
                    break;

                case "3":
                    System.out.println("3 消费");
                    System.out.println("请输入消费金额：");
                    money = scanner.nextDouble();
                    balance -= money;
                    Date date = new Date();
                    details += "消费金额\t-" + money + "\t" + simpleDateFormat.format(date) +"\t"+balance +"\n";
                    break;
                case "4":
                    System.out.println("4 退出");
                    loop = false;
                    break;
                default:
                    System.out.println("选择有误， 请重新选择");

            }
        }while(loop);
        System.out.println("=======退出了零钱通========");
    }


}
